class Product < ActiveRecord::Base
  attr_accessible :description, :price, :title, :product_url
  acts_as_predecessor
	has_many :line_products
	before_destroy :ensure_not_referenced_by_any_line_product

  validates :price, numericality: {greater_than_or_equal_to: 0.01}
  validates :title, uniqueness: true
	validates :product_url, uniqueness: true

	private
		def ensure_not_referenced_by_any_line_product
			if line_products.empty?
				return true
			else
				errors.add(:base, 'El configurador no esta vacio')
				return false
			end
		end
end
